package eduware.gui;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;

import eduware.Program;
import eduware.ctrl.Ctrl;
import eduware.dozent.MessageQueue;
import eduware.dozent.Mood;
import eduware.dozent.MoodState;

/**
 * A class to define what is shown when he sleeps
 * 
 * @author Dennis Gruner
 *
 */

public class Sleep extends JDialog implements ActionListener{
	
	/**
	 * Generated Version ID
	 */
	private static final long serialVersionUID = -7205078084982519444L;
	
	JButton sleep;
	
	private OutputField outputField = new OutputField();
	
	private int sleepCounter = 0;

	public Sleep(){
		
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		
		this.getContentPane().setLayout(new GridLayout(1, 1, 3, 3));

		this.setResizable(false);

		this.setSize(180, 180);

		this.setLocation(screenSize.width - this.getWidth(), screenSize.height - this.getHeight());

		this.setUndecorated(true);

		ImageIcon aboutButtonIcon = new ImageIcon("img/sleepbig.png");

		sleep = new JButton(aboutButtonIcon);

		sleep.addActionListener(this);

		sleep.setToolTipText("Ich bin am schlafen, bitte nicht wecken!");
		
		this.getContentPane().add(sleep);

		this.setAlwaysOnTop(true);
		this.pack();
		this.setVisible(false);
		
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == this.sleep) {
			this.sleepCounter++;
			if(this.sleepCounter<4) {
				
				MessageQueue.getInstance().addPrimaryMessage("Ich habe gesagt nicht aufwecken");
				MoodState.MOOD.increaseIndex(-3f - this.sleepCounter*2f);
				Mood.getInstance().trigger();
			}
			else {
				// wake up
				this.sleepCounter = 0;
				System.err.print("AUFWECKEN");
				Ctrl.getInstance().wakeUp();
			}
			
		}
		
	}

}

